<?php

namespace App\Repositories\Eloquent\Admin;

use App\Repositories\Eloquent\BaseModel;
use EasySwoole\ORM\AbstractModel;


class PositionModel extends AbstractModel
{
    use BaseModel;
    protected $tableName = 'k_adv_position';
    protected $connectionName = 'wr';
    protected $autoTimeStamp = true;
    protected $createTime = 'add_time';
    protected $updateTime = 'update_time';


    public function getList(array $where = [],$pageNum = PAGE_SIZE){
        $datas = $this->create()
            ->where($where)
            ->order('add_time','desc')
            ->_page($pageNum);
        return $datas;
    }


    public function getItemByName(string $name = ''){
        return $this->create()->get(['name'=> $name]);
    }

    public function getAllList()
    {
        $where['status'] = 1;
        $where['deleted'] = 0;
        $datas = $this->create()
            ->where($where)
            ->order('id', 'desc')
            ->all();

        $data = [];
        foreach ($datas as $item) {
            $data[] = $item->toArray();
        }
        return $data;

    }


}